﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SLTimeSystem
{
    public class TimeSystem : Singleton<TimeSystem>, IInitable
    {
        private TimeCenter center;
        public void Init()
        {
            GameObject go = new GameObject();
            go.name = "TimeCenter";
            MonoBehaviour.DontDestroyOnLoad(go);
            center = go.AddComponent<TimeCenter>();
        }

        public TimeAgent RegisterTimer(float time,int repeatCount,Action onTrigger)
        {
            TimeAgent agent = new TimeAgent();
            agent.TargetTime = time;
            agent.RepeatCount = repeatCount;
            agent.OnTrigger = onTrigger;
            center.Agents.Add(agent);
            return agent;
        }

        public FrameAgent RegisterFramer(float frame, int repeatCount, Action onTrigger)
        {
            FrameAgent agent = new FrameAgent();
            agent.TargetTime = frame;
            agent.RepeatCount = repeatCount;
            agent.OnTrigger = onTrigger;
            center.Agents.Add(agent);
            return agent;
        }

        public void RemoveTimer(TimerAgentBase timeAgent)
        {
            center.Agents.Remove(timeAgent);
        }
    }
}


